﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Tasks;
using RssV_m_v.ViewModel;
using Microsoft.Phone.Shell;
using System.Windows.Media.Imaging;
namespace RssV_m_v
{
    public partial class DetailNews : PhoneApplicationPage
    {
        public DetailNews()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                News currentNews = (News)PhoneApplicationService.Current.State["News"];
                if (currentNews.Title != null)
                    NewsTitle.Text = currentNews.Title;
                if (currentNews.UrlImage != null)
                    NewsImage.Source = new BitmapImage(new Uri(currentNews.UrlImage, UriKind.RelativeOrAbsolute));
                if (currentNews.Description != null)
                    NewsDescription.Text = currentNews.Description;
                base.OnNavigatedTo(e);
            }
            catch (Exception)
            {
                {
                    ((PhoneApplicationFrame)App.Current.RootVisual).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                }
                //throw;
            }

        }

       protected void OpenWebBrowser()
       {
           News currentNews = (News)PhoneApplicationService.Current.State["News"];
           WebBrowserTask task = new WebBrowserTask();
           task.URL = currentNews.Url;
           task.Show();
       }
       protected void MailSend()
       {
           EmailComposeTask task = new EmailComposeTask();
           News currentNews = (News)PhoneApplicationService.Current.State["News"];
           task.Subject = currentNews.Title;
           task.Body = "look : "+currentNews.Url;
           task.Show();
       }
       private void ButtonClickMail(object sender, RoutedEventArgs e)
       {
           MailSend();
       }

       private void ButtonClick(object sender, RoutedEventArgs e)
       {
           OpenWebBrowser();
       }
    }
}